﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MicroDal;
using System.Diagnostics;
using System.Data.Common;

namespace MicroDalTests.Benchmark
{
    [TestClass]
    public class GeneratedMaps
    {
        MapCache cache = new MapCache();

        [TestMethod, Ignore()]
        public void ConstructionOfReferenceTypes()
        {
            var dbReader = new TestDbReader("Id", 1, "Firstname", "Jesper", "Lastname", "Jensen", "Dob", new DateTime(1969, 9, 22));
            var sut = cache.Get<Person>();

            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < 1000000; i++)
            {
                var p = sut(dbReader);
            }
            sw.Stop();

            Assert.IsTrue(sw.Elapsed < new TimeSpan(0, 0, 3));
            Console.WriteLine("1.000.000 gennemløb med referencetype :{0}", sw.Elapsed);
        }

        [TestMethod, Ignore()]
        public void ConstructionOfValueTypes()
        {
            var dbReader = new TestDbReader("Id", 1);
            var sut = cache.Get<Int32>();

            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < 250000000; i++)
            {
                var p = sut(dbReader);
            }
            sw.Stop();
            Assert.IsTrue(sw.Elapsed < new TimeSpan(0, 0, 2));
            Console.WriteLine("250.000.000 gennemløb med valuetype :{0}", sw.Elapsed);
        }

        [TestMethod, Ignore()]
        public void ConstructionOfDynamicTypes()
        {
            var dbReader = new TestDbReader("Id", 1, "Firstname", "Jesper", "Lastname", "Jensen", "Dob", new DateTime(1969, 9, 22));
            Func<DbDataReader, dynamic> sut = DynamicMapper.Map;

            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < 1000000; i++)
            {
                var p = sut(dbReader);
            }
            sw.Stop();
            Assert.IsTrue(sw.Elapsed < new TimeSpan(0, 0, 10));
            Console.WriteLine("1.000.000 gennemløb med dynamictype :{0}", sw.Elapsed);
        }
    }

    public class Person
    {
        public int Id { get; set; }
        public string Firstname { get; set; }
        public string Lastname { get; set; }
        public DateTime Dob { get; set; }
    }
}
